package com.kefu.boss.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.boss.model.BossVersion;
import com.kefu.boss.service.BossVersionService;
import com.kefu.boss.vo.BossVersionInsertVo;
import com.kefu.boss.vo.BossVersionSearchVo;
import com.kefu.boss.vo.BossVersionUpdateVo;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import com.kefu.common.vo.DetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "业务支撑版本")
@RestController
@RequestMapping("boss/version")
public class BossVersionController extends AbstractBaseController {
    @Resource
    private BossVersionService bossVersionService;
    
    @PostMapping("/add")
    @ApiOperation(value = "新增", notes = "新增")
    public Result<String> add(@Validated @RequestBody BossVersionInsertVo bossVersionVo) {
    	logger.info("新增:{}", bossVersionVo);
    	
        bossVersionService.addVersion(bossVersionVo);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
    	logger.info("删除:{}", delete);
    	
        bossVersionService.deleteById(delete.getId());
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result<String> update(@Validated @RequestBody BossVersionUpdateVo bossVersionVo) {
    	logger.info("修改:{}", bossVersionVo);

    	bossVersionService.updateVersion(bossVersionVo);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    @ApiOperation(value = "详情", notes = "详情")
    public Result<BossVersion> detail(@Validated @RequestBody DetailVo detail) {

        BossVersion bossVersion = bossVersionService.findById(detail.getId());
        return ResultGenerator.genSuccessResult(bossVersion);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询", notes = "查询")
    public Result<Page<BossVersion>> list(@Validated @RequestBody BossVersionSearchVo search) {

        Page<BossVersion> page = bossVersionService.searchLambdaPage(search);
        return ResultGenerator.genSuccessResult(page);
    }
}
